package gui

import java.awt.Dimension
import java.awt.event.ActionEvent
import java.awt.event.ActionListener
import javax.swing.Timer
import scala.swing.Alignment
import scala.swing.BorderPanel
import scala.swing.GridBagPanel
import scala.swing.Label
import scala.swing.ProgressBar

/**
 * Diese Klasse erbt von BorderPanel und stellt eine
 * Statusbar dar. Ueber Setter- und Getter-Funktionen
 * lassen sich Statusmeldungen an den User ausgeben,
 * die dann fuer einen bestimmten Zeitraum angezeigt 
 * werden.
 */

class CustomStatusBar extends BorderPanel {

  var textInfo = new Label
  textInfo.text = ""
  textInfo.preferredSize = new Dimension(200, 24)
  textInfo.horizontalAlignment = Alignment.Left

  var progress = new ProgressBar {
    visible = true
    indeterminate = true
    labelPainted = false
    preferredSize = new Dimension(230, 16)
    maximumSize = new Dimension(230, 16)
  }
  progress.peer.setVisible(false)
  
  var labelPanel = new GridBagPanel() {
    preferredSize = new Dimension(220, 24)
    add(textInfo, new Constraints())
  }
  
  var progressPanel = new GridBagPanel() {
    preferredSize = new Dimension(250, 16)
    maximumSize = new Dimension(250, 16)
    add(progress, new Constraints())
  }

  this.add(labelPanel, BorderPanel.Position.West)
  this.add(progressPanel, BorderPanel.Position.East)
  
  var t:Timer = new Timer(2000, new ActionListener() {
    def actionPerformed(e: ActionEvent) : Unit = {
      t.stop()
      unsetMessage
    }
  })
  
  /**
   * Setzt den String mes fuer die Dauer von
   * dauer Millisekunden in die StatusBar
   */
  def setMessage(mes: String, dauer: Int) : Unit = {
    textInfo.text = mes
    t.setDelay(dauer)
    t.restart
  }
  
  def setMessage(mes: String) : Unit = {
    setMessage(mes, 2000)
  }
  
  def unsetMessage() : Unit = {
   textInfo.text = ""
  }
  
  def showProgress(b: Boolean) = {
    progress.peer.setVisible(b)
  }
 
}

   
 